home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / surfmodl / surfm203.arc / SURFSRC.ARC / PERSPECT.INC < prev    next >
Text File  |  1987-01-09  |  2KB  |  73 lines

  1. { The following variables are shared between Setorigin and Perspective }
  2. var D:             real;     { distance from eye to point viewed }
  3.     Cal, Cbe, Cgaa: real;     { cosines of the angles }
  4.     R:             real;
  5.     Zyflag:        boolean;  { true if the view is closely oriented to the
  6.                                X-Y plane }
  7.  
  8. procedure SETORIGIN;
  9. { Set the origin of the plot for the 3-D to 2-D transformation, and
  10.   pre-compute some angles
  11.   Setorigin, and the accompanying Perspective procedure, are derived
  12.   from algorithm 475, Communications of the ACM (Volume 17 No. 3, March 74)
  13.   and EPIC-3.
  14. }
  15. var Al, Be, Ga:    real;      { viewing angles }
  16.     Sga, Sbe:      real;      { sines of the viewing angles }
  17.  
  18. begin
  19.   if (Viewtype = 0) then begin
  20.     D := sqrt (sqr(Xfocal-Xeye) + sqr(Yfocal-Yeye) + sqr(Zfocal-Zeye));
  21.     Cal := (Xfocal-Xeye) / D;
  22.     Cbe := (Yfocal-Yeye) / D;
  23.     Cgaa := (Zfocal-Zeye) / D;
  24.     Al := arccos (Cal);
  25.     Be := arccos (Cbe);
  26.     Ga := arccos (Cgaa);
  27.     Sga := sin (Ga);
  28.     if (Sga >= 0.0001) then begin
  29.       R := 1 / Sga;
  30.       Zyflag := TRUE;
  31.     end else begin
  32.       Sbe := sin(Be);
  33.       R := 1 / Sbe;
  34.       Zyflag := FALSE;
  35.     end;
  36.   end; { if Viewtype }
  37. end;  { procedure SETORIGIN }
  38.  
  39. procedure PERSPECT (X, Y, Z: real; var Xt, Yt, Zt: real);
  40. { Do the 3-D to 2-D perspective transformation for a given node }
  41.  
  42. var Dnm:     real;       { denominator of the general fraction }
  43.  
  44. begin
  45.   if (Viewtype = 0) then begin
  46.     Dnm := (X - Xeye)*Cal + (Y - Yeye)*Cbe + (Z - Zeye)*Cgaa;
  47.     if (Dnm = 0.0) then
  48.       Dnm := 0.0001;
  49.     Zt := D / Dnm;
  50.     if (Zyflag) then begin
  51.       Xt := ((Xeye + Zt*(X-Xeye) - Xfocal)*Cbe - (Yeye + Zt*(Y-Yeye) - Yfocal)
  52.             *Cal) * R;
  53.       Yt := (Zeye + Zt*(Z-Zeye) - Zfocal) * R;
  54.     end else begin
  55.       Xt := ((Zeye + Zt*(Z-Zeye) - Zfocal)*Cal - (Xeye + Zt*(X-Xeye) - Xfocal)
  56.             *Cgaa) * R;
  57.       Yt := (Yeye + Zt*(Y-Yeye) - Yfocal) * R;
  58.     end;
  59.   end else if (Viewtype = 1) then begin
  60.     Xt := X;
  61.     Yt := Y;
  62.     Zt := -Z;
  63.   end else if (Viewtype = 2) then begin
  64.     Xt := X;
  65.     Yt := Z;
  66.     Zt := Y;
  67.   end else begin
  68.     Xt := Y;
  69.     Yt := Z;
  70.     Zt := -X;
  71.   end; { if Viewtype }
  72. end;  { procedure PERSPECT }
  73.